#!/bin/bash

# Ensure the data directory exists
mkdir -p /data

# Run the original MySQL entrypoint script
/usr/local/bin/docker-entrypoint.sh "$@"

# Wait for MySQL to be ready
until mysqladmin ping -h localhost -u root -psomewordpress --silent; do
  echo "Waiting for MySQL to be ready..."
  sleep 2
done

# Execute the initialization script if not already initialized
if [ ! -f /data/initialized ]; then
  echo "Running initialization scripts..."
  echo somepress\n | mysql -u root -p 12345678 < /docker-entrypoint-initdb.d/init.sql
  touch /data/initialized
fi